/**
 * create by ck on 2017/7/1.
 */
$(document).ready(function(){
    var schoolId    = xhTool.getQuery('schoolId'),
        $appCodeDom = $('#app_code'),
        appCode     = $appCodeDom.val(),
        $dataGrid   = new xhDataGrid($('#List'), 'School/getSchoolClass', {schoolId: schoolId, appCode: appCode});
    $appCodeDom.select2();
    $dataGrid.parseToolbar().init().activeButton(['bt_list_update_class'], []);
    //查看应用下班级
    $('#bt_view_class').click(function(){
        appCode = $appCodeDom.val();
        $dataGrid.reload({appCode: appCode});
    });
    //升级班级
    $('#bt_list_update_class').click(function(){
        if(xhExtra.buttonDisabled($(this))) return false;
        var parameter = {
            schoolId: schoolId,
            appCode: appCode,
            classId: $dataGrid.getSelectValues('sClassId'),
            className: $dataGrid.getSelectValues('sClassName'),
            tchId: $dataGrid.getSelectValues('iTchId')
        };
        xhExtra.askChangeStatus('School/updateClassName', parameter, $dataGrid, '是否确认升级？', function(data){
            var content = '';
            $.each(data, function(index, row){
                content += `<tr><td>${row.oldClassName}</td><td>${row.newClassName}</td></tr>`;
            });
            window.top.swal({
                title: '升级成功！',
                type: 'success',
                html: `<table class="table table-striped">
                    <tr>
                        <th style="text-align: center">原班级名</th>
                        <th style="text-align: center">现班级名</th>
                    </tr>
                    ${content}
                </table>`
                // onOpen: function(){
                //     setTimeout(function(){
                //         console.log('success');
                //         $(window.top.document, '#modalContentId').css({
                //             'height': '400px',
                //             'overflow-y': 'scroll'
                //         });
                //         $(window.top.document, '.swal2-modal').css('min-height', null);
                //     }, 2000);
                // }
            });
        });
    });
});